package com.wx.algorithm.linked;

import com.wx.algorithm.linked.node.OneNode;
import com.wx.algorithm.linked.node.OneNodeList;

/**
 * @desc: 单链表反转
 * @author: wx
 * @time: 2019/12/7 10:39 AM
 */
public class Reverse {


    public static void main(String args[]) {
        //level
        OneNodeList<String> oneNodeList = new OneNodeList<>();
        oneNodeList.add("1");
        oneNodeList.add("2");
        oneNodeList.add("3");
        oneNodeList.add("4");
        oneNodeList.add("5");


        OneNode<String> node = oneNodeList.getNode(0);
        OneNode<String> tmpNode = null;
        while (node != null) {

            OneNode<String> next = node.getNext();
            if (next == null) {
                node.setNext(tmpNode);
                break;
            }

            OneNode<String> next2 = next.getNext();

            node.setNext(tmpNode);

            next.setNext(node);

            tmpNode = next;

            node = next2;

        }

        while (node != null) {
            System.out.println(node.getE());
            node = node.getNext();
        }
    }





}
